 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.list.DingDanPeiSongMingXi"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <style type="text/css">
        div.group-info {
            margin-top: 10px !important;
            margin-bottom: 0px !important;
        }
        input.innerInput {
            width: 100%;
        }
        div.tablediv {
            width: 1500px;
            margin: auto;
            margin-top: 20px;
            margin-bottom: 20px;
            border-top: 1px solid #cecece;
        }
        td.ui-sgcollapsed.sgexpanded>div, td.ui-sgcollapsed.sgcollapsed>div {
            width: 20px !important;
        }
        tr.ui-subgrid>td.subgrid-data {
            border-right: 1px solid #cecece;
            border-bottom: 1px solid #cecece;
        }
        div.tablediv div.ui-jqgrid-bdiv, div.tablediv div.ui-jqgrid-hdiv {
            border-right: 0px none;
            border-bottom: 0px none;
        }
        span.addRow {
            width: 20px;
            display: block;
            margin: auto;
            cursor: pointer;
        }
        td.subgrid-data {
            background-color: #FDF5E6;
        }
        div.tablediv {
            border-right: 1px solid #cecece;
            border-bottom: 1px solid #cecece;
        }
    </style>
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
     <section class="content-header">
	<h1>已完成订单</h1>
	<ol class="breadcrumb">
		<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
		<li class="active"><a href="#">交易</a></li>
		<li class="active"><a href="#">订单管理</a></li>
		<li class="active"><a href="#">订单查询</a></li>
		<li class="active"><a href="#">已完成订单</a></li>
	</ol>
	</section>
	
    <section class="content">
        <div class="box box-success">
            <div class="box-body">
                <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>" />
                    </div>
                    <div class="textalign">医疗机构名称：</div>
                	<div class="boxinput">
                		<input type="text" class="textinput" id="hospName" name="hospName" placeholder="医疗机构名称" />
                	</div>
               
                	<div class="textalign"><spring:message code="message.listForm.YiLiaoJiGouDiQu"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                       <table style="width:100%;">
                           <tr>
                              <td style="width:33%">
                                <select class="textinput" id="area1" name="area1" disabled="disabled">
                                	<option value="${area.areaId}">${area.areaName}</option>
                                </select>
                              </td>
                              <td style="width:33%">   
                                <select class="textinput" id="area2" name="area2" ></select>
                                </td>
                              <td style="width:33%">
                                <select class="textinput" id="area3" name="area3" ></select>
                              </td>
                           </tr> 
                        </table>     
                    </div>
                     </div>
                <div class="input" style="margin-top:-5px;">
                <div class="textalign1"><spring:message code="message.listForm.PeiSongQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="delCompName" name="delCompName" placeholder="<spring:message code="message.listForm.PeiSongQiYe"/>" />
                    </div>
                    
                           
                	
                    <div class="textalign" >  
                   		<button type="button" onclick="gridSerch();" class="btn btn-success btn-sm"  id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
   </section>
    
   <%@ include file="/WEB-INF/component/commonJS.jsp"%>
   <script type="text/javascript">
   $(function () {
	   
	   $("#area2").HNSelect({
           url: "${ctx}/selectController/getArea.html", 
           data: { ID: '${sysAreaId}' }, 
           defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
           defaultselect: "",
           func: function () {
               $("#area3").HNSelect({
                   parent_selector: "#area2", 
                   url: "${ctx}/selectController/getArea.html", 
                   dataid: "ID", 
                   defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                   defaultselect: ""
               });
           }
       });
	   
       //绑定回车
       $('#drugName,#prodComp,#hospName,#area1,#area2,#area3,#delCompName').bind('keydown', function(event) {
           if (event.keyCode == "13") {
               $('#selectDicCompType').click();
           }
       });  
     
       $("#drugName").focus();//加载页面光标在第一个查询框内
       
       $("#gridlist").jqGrid({
           url: "getOrdersDetailListOldByProComp.html",
           mtype: "POST",
           datatype: "json",
           autowidth: true,
           shrinkToFit: false,
           height: 350,
           colNames: [
                'orderCode',
                '状态',
                '<spring:message code="message.listForm.CaiGouJia"/>',
                '<spring:message code="message.listForm.CaiGouShuLiang"/>',
                '<spring:message code="message.listForm.CaiGouJinE"/>',
                '<spring:message code="message.listForm.yaoPinBianMa"/>',
                '<spring:message code="message.listForm.tongYongMing"/>', 
                '<spring:message code="message.listForm.jiXing"/>',
                '<spring:message code="message.listForm.guiGe"/>',
                '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
                '<spring:message code="message.listForm.baoZhuangDanWei"/>', 
                '<spring:message code="message.listForm.shengChanQiYe"/>',
                '国药准字',
                '<spring:message code="message.listForm.CaiGouXianJia"/>',
                '最高零售限价',
                'orderStatus',
                'confirmRemark',
                '医疗机构名称',
                '医疗机构地区',
                '配送企业'
            ],
            colModel: [
                { name: 'orderCode', width: 60, align: "right",sortable:false, hidden:true },
                { name: 'orderStatus', width: 80, align: "center" ,sortable:false},
                { name: 'proPrice', width: 60, align: "right",sortable:false,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'proCount', width: 60, align: "center",sortable:false},
                { name: 'orderMoney', width: 60, align: "right",sortable:false,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'drugCode', width: 140, align: "center",hidden:true,sortable:false/*,
                    formatter:function(cellvalue, options, row){
                        return drugInfoLink(cellvalue);
                    }*/
                },
                { name: 'drugName', width: 140, align: "left" ,sortable:false },
                { name: 'formName', width: 60 , align: "center",sortable:false},
                { name: 'specName', width: 60, align: "center" ,sortable:false},
                { name: 'factor', width: 60, align: "center" ,sortable:false},
                { name: 'unitName', width: 60, align: "center" ,sortable:false},
                { name: 'prodCompname', width: 180, align: "left",hidden:true,sortable:false/*,
                    formatter:function(cellvalue, options, row){
                        return compInfoLink(row.prodCompcode, cellvalue, 1);
                    }*/
                },
                { name: 'drugMedicine', width: 80, align: "center" ,sortable:false},
                { name: 'proPriceLimit', width: 60,align:"right",sortable:false, hidden:true,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'retailPriceLimit', width: 60,align:"right",sortable:false, hidden:true,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'orderStatus', width: 60, align: "center" ,sortable:false, hidden:true},
                { name: 'confirmRemark', width: 60, align: "center" ,sortable:false, hidden:true},
                { name: 'hospName', width: 200, align: "center",sortable:false/*,
                    formatter:function(cellvalue, options, row){
                        return hospInfoLink(row.hospCode, cellvalue, 1);
                    }*/
                },
                { name: 'hospArFullname', width: 250, align: "center",sortable:false},
                { name: 'delCompName', width: 250, align: "center",sortable:false/*,
                    formatter:function(cellvalue, options, row){
                        return compInfoLink(row.prodCompcode, cellvalue, 1);
                    }*/
                },
            ],
           rowNum: 20,
           rowList: [10, 20, 50, 100],
           rownumbers: true,
           pager: "#gridpage",
          // multiselect: false, 
           viewrecords: true,
           gridComplete: function(){
               //序号列宽度自适应（参数为jqgridID）
               // autoRNWidth("gridlist");
           }, 
           caption: "已完成订单明细列表",
           jsonReader: {
               repeatitems: false,
               id: "orderCode"
           },
           subGrid: true,
           subGridOptions: {
               reloadOnExpand : false
           },
           beforeSelectRow: function(rowid, e) {
               return true;   
           },
           subGridRowExpanded: function(subGridId, rowId) {
               $("tr.ui-subgrid>td:not(.subgrid-data)").remove();
               $("tr.ui-subgrid>td.subgrid-data").attr("colspan", 16);
               
               var subTableId = "subTable_" + rowId;
               $("#" + subGridId).append("<table id='" + subTableId + "' class='scroll'></table>");
               
               var title = [];
               var model = [];
               var datatype = "local";
               
               var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
               
               if (rowdata.orderStatus == 4) {
            	   title = ['拒绝人','拒绝时间','拒绝配送理由'];
            	   model = [
                        { name: 'delUser', width: 100, align: "left",sortable:false, 
                        	formatter:function(cellvalue, options, row){
                                return rowdata.delUser || "";
                            }
                        },
                        { name: 'delDatetime', width: 160, align: "center",sortable:false, 
                        	formatter:function(cellvalue, options, row){
                                return rowdata.delDatetime || "";
                            }
                        },
						{ name: 'confirmRemark', width: 632, align: "left",sortable:false,
                        	formatter:function(cellvalue, options, row){
                                return rowdata.confirmRemark || "";
                            }
						}
            	   ];
            	   datatype = "local";
               } else {
            	   title = ['状态','批号','有效期','配送数量','配送人','配送时间','到货数量','确认人','确认时间','发票号','备注'];
                   model = [
						{ name: 'isRecepted', width: 80, align: "center" ,sortable:false},
						{ name: 'approveCode', width: 100, align: "center",sortable:false },
						{ name: 'credential', width: 100, align: "center",sortable:false},
						{ name: 'delCount', width: 80, align: "center",sortable:false },
						{ name: 'delUser', width: 250, align: "center",sortable:false },
						{ name: 'delDatetime', width: 140, align: "center",sortable:false },
		                { name: 'recpCount', width: 80, align: "center",sortable:false },
                        { name: 'recpUser', width: 200, align: "center",sortable:false },
                        { name: 'recpDatetime', width: 143, align: "center",sortable:false },
						{ name: 'invoiceNo', width: 100, align: "center",hidden:true,sortable:false },
						{ name: 'remarks', width: 300, align: "center",sortable:false }    
                   ];
                   datatype = "json";
               }
               
               $("#" + subTableId).jqGrid({
            	   url: "${ctx}/purOrderInfo/getOrderDelList.html",
                   mtype: "POST",
                   datatype: datatype,
                   postData: {"orderCode" : rowId},
                   autowidth: true,
                   shrinkToFit: false,
                   height: "auto",
                   colNames: title,
                   colModel: model,       
                   rownumbers: true,
                   beforeSelectRow: function(rowid, e) {
                       return true;    //  子表格无选中状态
                   }
               });
               
               if (rowdata.orderStatus == 4) {
            	   $("#" + subTableId).addRowData(0, {});
               }
               
           }
       });
       $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
       $(window).trigger("resize");
       
       $("html").scrollTop(305);
   });
   
   //查询
   function gridSerch() {
       var drugCode = $.trim($("#drugCode").val());
       var drugName = $.trim($("#drugName").val());
       var prodComp = $.trim($("#prodComp").val());
       var hospName = $.trim($("#hospName").val());
       var delCompName = $.trim($("#delCompName").val());
       var area1 = $.trim($("#area1").val());
       var area2 = $.trim($("#area2").val());
       var area3 = $.trim($("#area3").val());
       $("#gridlist").jqGrid('setGridParam',{  
           datatype:'json',
           postData:{
               "drugCode":drugCode,
               "drugName":drugName,
               "compName":prodComp,
               "hospName":hospName,
               "delCompName":delCompName,
               "area1":area1,
               "area2":area2,
               "area3":area3
           },
           page:1
       }).trigger("reloadGrid"); //重新载入  
   }
   </script>
        
</body>
</html>
 